#include "com_voe_VoiceEngine.h"
#include "voe_base.h"
#include "jni_api.h"
#include "TraceCallbackImpl.h"

static TraceCallbackImpl _TraceCallback;

#include <windows.h>

/*
 * Class:     com_voe_VoiceEngine
 * Method:    Create
 * Signature: ()Lcom/voe/VoiceEngine;
 */
JNIEXPORT jlong JNICALL Java_com_voe_VoiceEngine_Create
  (JNIEnv* env, jclass cls)
{
	return (jlong)webrtc::VoiceEngine::Create();
}

/*
 * Class:     com_voe_VoiceEngine
 * Method:    Delete
 * Signature: (Lcom/voe/VoiceEngine;)Z
 */
JNIEXPORT jboolean JNICALL Java_com_voe_VoiceEngine_Delete
  (JNIEnv* env, jclass cls, jlong p)
{
	webrtc::VoiceEngine* pEngine = (webrtc::VoiceEngine*)p;
	return webrtc::VoiceEngine::Delete(pEngine);
}

/*
 * Class:     com_voe_VoiceEngine
 * Method:    SetTraceFilter
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoiceEngine_SetTraceFilter
  (JNIEnv* env, jclass cls, jint filter)
{
	return webrtc::VoiceEngine::SetTraceFilter(filter);
}

/*
 * Class:     com_voe_VoiceEngine
 * Method:    SetTraceFile
 * Signature: (Ljava/lang/String;Z)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoiceEngine_SetTraceFile
  (JNIEnv* env, jclass cls, jstring fileNameUTF8, jboolean addFileCounter)
{
	return (jint)webrtc::VoiceEngine::SetTraceFile(JniHelper::j2c_string(env, fileNameUTF8).c_str(), addFileCounter!=0);
}

/*
 * Class:     com_voe_VoiceEngine
 * Method:    SetTraceCallback
 * Signature: (Lcom/voe/TraceCallback;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoiceEngine_SetTraceCallback
  (JNIEnv* env, jclass cls, jobject obj)
{
	jint result = 0;
	do 
	{

		if(obj)
		{
			if(_TraceCallback.set(env, obj))
			{
				result = (jint)webrtc::VoiceEngine::SetTraceCallback(&_TraceCallback);
			}
			else
			{
				result = JCB_Err_Set;
			}
		}
		else
		{
			result = (jint)webrtc::VoiceEngine::SetTraceCallback(0);
		}

	} while (false);

	return result;
}

